package com.servlet.user;

import com.dao.UserDao;
import com.entity.User;
import com.util.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author admin
 */
@WebServlet(name = "UserSelectOneServlet",urlPatterns = "/UserSelectOneServlet.filter")
public class UserSelectOneServlet extends HttpServlet {
//    private String encoding;



    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String u_id = request.getParameter("u_id");
        System.out.println("UserSelectOneServlet");
        SqlSession session = MybatisUtil.getSession();
        UserDao userDao = session.getMapper(UserDao.class);
        User updateUser = userDao.selectUserOne(Integer.parseInt(u_id));
        System.out.println(updateUser.toString());
        request.setAttribute("updateUser",updateUser);
        request.getRequestDispatcher("/WEB-INF/page/user.jsp").forward(request,response);
    }
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
